#include"../header.h"


int main(int argc, char const *argv[])
{
    int fid=socket(AF_INET,SOCK_DGRAM,0);
    printf("fid=%d\n",fid);

    int value=0;
    int size=sizeof(value);
    getsockopt(fid,SOL_SOCKET,SO_BROADCAST,&value,&size);
    value=1;
    setsockopt(fid,SOL_SOCKET,SO_BROADCAST,&value,size);
    getsockopt(fid,SOL_SOCKET,SO_BROADCAST,&value,&size);
    printf("value=%d\n",value);


    struct sockaddr_in faddr={0};
    faddr.sin_addr.s_addr=INADDR_BROADCAST;
    faddr.sin_family=AF_INET;
    faddr.sin_port=htons(atoi(argv[1]));

    struct sockaddr_in kaddr={0};
    faddr.sin_addr.s_addr=INADDR_BROADCAST;;
    faddr.sin_family=AF_INET;
    faddr.sin_port=htons(atoi(argv[2]));
    
    char bufv[128]="";
    while (1)
    {   
        printf("请输入要广播的信息:");
        scanf("%s",bufv);
        sendto(fid,bufv,strlen(bufv),0,(struct sockaddr*)&faddr,sizeof(faddr));
        sendto(fid,bufv,strlen(bufv),0,(struct sockaddr*)&kaddr,sizeof(kaddr));
        bzero(bufv,sizeof(bufv));  
        printf("数据已发送\n");
    }
    close(fid);
    return 0;
}
